<?php
/**
  * User: sunkejun
 * Date: 13-12-8
 * Time: 下午7:01
 */
class AdService{

    public  $dbutil;
    function __construct($dbutil){
        $this->dbutil =  $dbutil;
    }


    /**
     * 返回首页轮播的html
     * @return string 返回生成html
     */
    function getImgshowHtml(){
    	$sql = " SELECT tc.*,asite.site_name FROM ad_content tc RIGHT JOIN ad_sites asite ON tc.ad_site_id = asite.site_id WHERE asite.site_name = '首页编辑推荐' ORDER BY tc.ad_index LIMIT 5";
     	$result =  $this->dbutil->get_results($sql);
    	$restr;
    	
    	if(!empty($result)){
    		  $length=0;
    		  foreach ($result as $rs){
    		  	
    		  	$length++;
    		 	 $restr.="<div class='event-item' style='display: block;'> 	<a target='blank' href='".$rs->ad_href."' class='banner'>";
    		 	 $restr.=" <img src='";
				 if($rs->ad_file_type == 0){
					 $restr.= WEBSITE_URL . "upload/" . $rs->ad_file_location;
				 }else{
				 	$restr.=  $rs->ad_file_location;
				 }	
				 $restr.="' class='photoshow 'alt='' />";
				 $restr.="</a> 	<div class='imgshouw-text'> <h3>".$rs->ad_title."</h3><p>".$rs->ad_description."</p></div></div>";
    			}
    			$restr.='<div class="switch-tab">';
    			for($i=1;$i<=$length;$i++){
    				if($i==1){
    					$restr.='<a href="#" onclick="return false;" class="current">'.$i.'</a>';
    				}else{
    					$restr.='<a href="#" onclick="return false;" >'.$i.'</a>';
    				}
    			}
    			$restr.='</div>';
    	}
    	return $restr;
    }
}